package com.downbox.domain;

import jakarta.persistence.*;
import lombok.Data;
import java.time.LocalDateTime;

/**
 * 内容实体类
 */
@Data
@Entity
@Table(name = "content")
public class Content {
    @Id
    private String id;

    @Enumerated(EnumType.STRING)
    private ContentType type;

    @Column(name = "payload", columnDefinition = "JSON")
    private String payload;

    @Column(name = "tags_json", columnDefinition = "JSON")
    private String tagsJson;

    @Enumerated(EnumType.STRING)
    private ContentSrc src;

    private Integer weight;

    @Column(name = "created_at")
    private LocalDateTime createdAt;

    public enum ContentType {
        TEXT,
        IMAGE,
        AUDIO
    }

    public enum ContentSrc {
        OFFICIAL,
        USER
    }

    @PrePersist
    public void prePersist() {
        if (createdAt == null) {
            createdAt = LocalDateTime.now();
        }
    }
}